package cn.blog.dao.back;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.blog.dao.conn.DataManager;
import cn.blog.dao.conn.ParamSet;
import cn.blog.dao.conn.RowDatas;
import cn.blog.entity.origin.User;

/**
 * 后台博客管理DAO层
 * @author zjk
 *1.查询用户细信息
 */
public class ManageblogDao extends DataManager {
	private RowDatas<User> blog;
	private RowDatas<String> oneRow;
	/**
	 * 无参构造 初始化
	 */
	public ManageblogDao() {
		blog = new UserData();
		oneRow = new oneRowData();
	}
	/**
	 * 1.查询用户细信息
	 * 查询所有用户ID，用户名，注册时间，电话，状态五个信息
	 * @return
	 */
	public List<User> getUsers() {
		String sql = "select user_account,user_name,user_reg_time,"
				+ "user_phone,user_state from tb_user";
		return queryList(sql, blog);
	}
	public int updateState(int state,String account) {
		String sql = "UPDATE tb_user SET user_state = ? WHERE user_account = ?";
		return updateExecuted(sql, new ParamSet(state,account));
	}
	
	/**
	 * 获取用户数据
	 * @author zjk
	 *
	 */
	private class UserData implements RowDatas<User> {

		@Override
		public User getRowData(ResultSet rs) throws SQLException {
			User user = new User();
			user.setUserAccount(rs.getString(1));
			user.setName(rs.getString(2));
			user.setUserRegTime(rs.getDate(3));
			user.setPhone(rs.getString(4));
			user.setState(rs.getInt(5));
			return user;
		}

	}
	private class oneRowData implements RowDatas<String>{

		@Override
		public String getRowData(ResultSet rs) throws SQLException {
			
			return rs.getString(1);
		}
		
	}
}
